﻿namespace Pottery.Module.Infrastructure.Models
{
    using System;
    using System.Data.SqlTypes;
    using System.Runtime.Serialization;
    using Pottery.Model.Infrastructure;

    /// <summary>
    /// Storage
    /// </summary>
    [DataContract]
    public class Storage : IValidatable, IAssignable, INullable
    {
        #region Constructor

        /// <summary>
        /// Default constructor
        /// </summary>
        public Storage() { }

        /// <summary>
        /// Constructor with parameters
        /// </summary>
        /// <param name="bankAcc">BankAccount</param>
        /// <param name="sqr">Square of the store</param>
        /// <param name="addr">Store address</param>
        /// <param name="petname">Store PetName</param>
        /// <param name="storenum">Number of the store</param>
        public Storage(string bankAcc, double sqr, string addr, string petname, int storenum, string phone)
        {
            BankAccount = bankAcc;
            Square = sqr;
            Address = addr;
            PetName = petname;
            StoreNumber = storenum;
            Phone = phone;
        }

        #endregion

        #region Properties

        [DataMember(Order = 4)]
        public string BankAccount
        {
            get { return m_BankAccount; }
            set
            {
                if (!IsNull)
                    m_BankAccount = value;
            }
        }

        [DataMember(Order = 5)]
        public double Square
        {
            get { return m_Square; }
            set
            {
                if (!IsNull)
                    m_Square = value;
            }
        }

        [DataMember(Order = 3)]
        public string Address
        {
            get { return m_Address; }
            set
            {
                if (!IsNull)
                    m_Address = value;
            }
        }

        [DataMember(Order = 1)]
        public string PetName
        {
            get { return m_PetName; }
            set
            {
                if (!IsNull)
                    m_PetName = value;
            }
        }

        [DataMember(Order = 2)]
        public int StoreNumber
        {
            get { return m_StoreNumber; }
            set
            {
                if (!IsNull)
                    m_StoreNumber = value;
            }
        }

        [DataMember(Order = 6)]
        public string Phone
        {
            get { return m_Phone; }
            set
            {
                if (!IsNull)
                    m_Phone = value;
            }
        }

        #endregion

        #region IValidate implementation

        public bool Validate()
        {
            bool isValid = true;

            if (string.IsNullOrEmpty(BankAccount) || string.IsNullOrWhiteSpace(BankAccount))
                isValid = false;

            return isValid;
        }
        #endregion

        #region IAssignTo implementation
        /// <summary>
        /// Copy data from current object to object in param.
        /// </summary>
        /// <param name="obj">object to change </param>
        public void AssignTo(object obj)
        {
            if (IsNull)
                throw new InvalidOperationException();

            if (obj == null)
                throw new ArgumentNullException("obj");

            if (obj is Storage)
            {
                Storage item = obj as Storage;

                item.BankAccount = m_BankAccount;
                item.Square = m_Square;
                item.Address = m_Address;
                item.PetName = m_PetName;
                item.StoreNumber = m_StoreNumber;
                item.Phone = m_Phone;

                item.m_Null = false;

                return;
            }
        }

        #endregion

        #region INullable implementation

        public bool IsNull
        {
            get { return m_Null; }
        }

        public static Storage Null
        {
            get
            {
                Storage store = new Storage();
                store.m_Null = true;
                return store;
            }
        }
        #endregion

        #region Private Fields

        private int m_StoreNumber = default(int);
        private string m_BankAccount = default(string);
        private string m_PetName = default(string);
        private string m_Address = default(string);
        private string m_Phone = default(string);
        private double m_Square = default(double);
        private bool m_Null = false;

        #endregion

    }
}
